package cn.rick.mapper;

import cn.rick.entity.SysRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 角色信息表 Mapper 接口
 * </p>
 *
 * @author house_store
 * @since 2022-10-19 14:39:46
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    /**
     * 通过用户id查询roleIds
     *
     * @param userId
     * @return
     */
    List<Long> getRoleIdsByUserId(Long userId);

    @Select("SELECT r.*\n" +
            "        FROM `sys_user` u\n" +
            "                 INNER JOIN sys_user_role ur ON ur.user_id = u.user_id\n" +
            "                 INNER JOIN sys_role r ON r.role_id = ur.role_id\n" +
            "        where u.user_id = #{userId}")
    List<SysRole> findRolesByUserId(@Param("userId") Long userId);

}
